<?php
//--------------include framework_config file--------------------------------------------------------------
include("bo/application/app_config.php");
include("bo/application/app_constant.php");
include ("bo/library/config/fw_config.php");

$smarty->template_dir = TEMPLATE_DIR_FO;
$smarty->compile_dir  = TEMPLATE_C_DIR_FO;
$smarty->config_dir  = TEMPLATE_DIR_FO;

//////////////////////////////////////////////////////////////////
// Custom error handler to log PEAR errors
if (!defined('PEAR_ERROR_LOG_FILE')) {
	define('PEAR_ERROR_LOG_FILE', APPLICATION_DIR.'/errors.log');
}
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'customErrorHandler');
function customErrorHandler($error) {
	if (is_a($error,'PEAR_Error')) {
		$message = $error->getUserInfo();
	} else {
		$message = $error;
	}
	$log = '';
	$log .= "-------------------\n";
	$log .= 'Request : '.$_SERVER['REQUEST_URI'].'	 Time : '.date('Y-m-d H:i:s')."\n";
	$log .= "-------------------\n";
	$log .= $message."\n";
	file_put_contents(PEAR_ERROR_LOG_FILE, $log, FILE_APPEND);
}

//-------------------------route controller----------------------------------------------------------------
$controller = isset($_REQUEST["m"])? strtolower($_REQUEST["m"])	: "";
$action	 = isset($_REQUEST["a"])? strtolower($_REQUEST["a"])	: "";

//register var modules, action and args
DRX::register("controller",$controller);
DRX::register("action",$action);

include_once "config.php";
//include_once "autorisation.php";

//--------------include language file----------------------------------------------------------------------
if (DRX_MultiLanguage::getLanguage() != '')
{
	//include_once (APPLICATION_DIR_FO."/application/language/".DRX_MultiLanguage::getLanguage()."/common.php");
    include_once (APPLICATION_DIR_FO."/application/language/vn/common.php");
}

$business = Business_Solution::getSubItem(0);
$menuCAT = CATEGORY::getSubItem(0);
$smarty->assign('menuBS', $business);
$smarty->assign('menuCAT', $menuCAT);
$smarty->assign('Utils', new Utils());


$topApp = new Application();
$topDesign = new Application();
$topTech = new Application();

$topApp->getRootItem(Application::TYPE_APPLICATION);
$topDesign->getRootItem(Application::TYPE_DESIGN);
$topTech->getRootItem(Application::TYPE_TECHNOLOGY);

$smarty->assign('topApp', $topApp);
$smarty->assign('topDesign', $topDesign);
$smarty->assign('topTech', $topTech);

if ($action == "" && file_exists("application/controller/index.php"))
{

	$action = "index";
}

if($controller == ""){
    $controller = "home";
}
$actionBanner = $action;
$type = Request::get("type");
if($type == "technology" || $type == "design"){
    $actionBanner = $type;
}
$banner = new Banner();
$banner->getBanner($controller, $actionBanner);
$smarty->assign('banner', $banner);

if ($action == "" && file_exists("application/controller/".$controller.".php"))
{

	require_once("application/controller/".$controller.".php");
}
elseif(file_exists("application/controller/".$controller."/".$action.".php"))
{
    
	require_once("application/controller/".$controller."/".$action.".php");
}
else
{
	require_once("application/controller/home/index.php");
}